#include<bits/stdc++.h>
using namespace std;
long long a[200005],c[200005];
long long b[200005];
int T;
int n;
int bzf=0;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T>0){
        bzf=0;
        cin>>n;
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++){
            for(int j=i-1;j>=0;j--){
                if(a[j]==a[i]){
                    bzf=bzf+a[i];
                    continue;
                }
            }
        }
        cout<<bzf<<endl;
        T--;
    }
    return 0;
}
